#!/usr/bin/python3.8.9
# -*- coding: utf-8 -*-

# @Author  : Tina Yu
# @Time    : 2022-5-4 16:01
import logging
import os

from homework.task_api.utils_api.read_file import ReadFile

# 初始化句柄
logger = logging.getLogger(__name__)

# 获取日志放置的路径
file_path = os.sep.join([ReadFile.get_file_path(), "logs"])

if not os.path.exists(file_path):
    os.mkdir(file_path)

# 拼接log文件和句柄
file_handle = logging.FileHandler(filename=file_path + "/task_api.log", encoding="utf-8")

# 日志的输出格式
formatter = logging.Formatter(
    '[%(asctime).19s] %(process)d:%(levelname).1s %(filename)s:%(lineno)d:%(funcName)s: %(message)s')

# 日志格式与句柄的绑定
file_handle.setFormatter(formatter)

# 控制台句柄定义
steam_handler = logging.StreamHandler()

# 日志格式与句柄的绑定
steam_handler.setFormatter(formatter)

# 与logger进行绑定
logger.addHandler(file_handle)
logger.addHandler(steam_handler)

# 设置展示/写入文件的日志的级别
logger.setLevel(logging.INFO)
